<template>
  <n-card :bordered="false" class="proCard">
    <BasicForm @register="register" @submit="handleSubmit" @reset="handleReset">
      <template #statusSlot="{ model, field }">
        <n-input v-model:value="model[field]" />
      </template>
    </BasicForm>

    <BasicTable
      :columns="columns"
      :request="loadDataTable"
      :row-key="(row:ListData) => row.id"
      :dataSource="dataform"
      ref="actionRef"
      @update:checked-row-keys="onCheckedRow"
      :scroll-x="1090"
    >

      <template #toolbar>
        <n-button type="primary" @click="reloadTable">刷新数据</n-button>
      </template>
    </BasicTable>

  </n-card>
</template>

<script lang="ts" setup>
  import { nextTick, ref } from 'vue';
  import { BasicTable } from '@/components/Table';
  import { BasicForm, FormSchema, useForm } from '@/components/Form/index';
  import { columns, ListData } from './columns';
  import {getDfltDlye } from '@/api/dataInfo/flightInfo';
import { ResultEnum, ipAddress } from '@/enums/httpEnum';
import {  useMessage } from 'naive-ui';
const message = useMessage();
  const timestamp =  ref(1496419200000)

  const schemas: FormSchema[] = [

    {
      field: 'timestamp',
      component: 'NDatePicker',
      label: '查询时间',
      componentProps: {
        type: 'date',
        clearable: true,
        defaultValue: timestamp.value,
        onUpdateValue: (e: any) => {
          console.log(e);
        },
      },
    },
    // {
    //   field: 'apat',
    //   component: 'NRadioGroup',
    //   label: '机场属性',
    //   componentProps: {
    //     options: [
    //       {
    //         label: '国际',
    //         value: '2401',
    //       },
    //       {
    //         label: '地区',
    //         value: '2402',
    //       },
    //       {
    //         label: '国内',
    //         value: '2403',
    //       },
    //       {
    //         label: '混合',
    //         value: '2404',
    //       }
    //     ],
    //   },
    // },本页面无航班属性选择
  ];

  const actionRef = ref();
  const dataform = ref();

  const [register, { getFieldsValue }] = useForm({
    gridProps: { cols: '1 s:1 m:2 l:3 xl:4 2xl:4' },
    labelWidth: 80,
    schemas,
  });

  const loadDataTable = async (res) => {
    await nextTick(); // Wait for the DOM to update
    const rese = await getDfltDlye({ ...getFieldsValue(), ...res });//这里改接口
    if(rese.code == ResultEnum.SUCCESS){
      var matchedName = ipAddress[rese.msg];
      message.success('正在访问'+matchedName+'的接口');
    }
    return rese.data;
  };

  function onCheckedRow(rowKeys) {
    console.log(rowKeys);
  }

  function reloadTable() {
    actionRef.value.reload();
  }

  async function handleSubmit() {
    reloadTable();
}


  function handleReset(values: Recordable) {
    console.log(values);
  }

  

</script>

<style lang="less" scoped></style>
